package cn.ai.shoes.client.service.impl;

import cn.ai.shoes.client.entity.vo.ComfyuiLogPageVo;
import cn.ai.shoes.client.service.ComfyuiLogService;
import cn.ai.shoes.client.entity.ComfyuiLog;
import cn.ai.shoes.client.mapper.ComfyuiLogMapper;

import cn.ai.shoes.common.core.mybatis.LambdaQueryWrapperX;
import cn.ai.shoes.core.pojo.entity.MyUser;
import cn.ai.shoes.core.service.UserService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;

@Service
public class ComfyuiLogServiceImpl extends ServiceImpl<ComfyuiLogMapper, ComfyuiLog> implements ComfyuiLogService {
    public static final int ORDERBY_EXCUTETIME = 1;

    @Override
    public IPage<ComfyuiLog> pageComfyuiLog(ComfyuiLogPageVo imageQueryVo) {
        Page<ComfyuiLog> page = new Page<>(imageQueryVo.getPageNum(), imageQueryVo.getPageSize());
        return getBaseMapper().selectPage(page, new LambdaQueryWrapperX<ComfyuiLog>()
                .likeIfPresent(ComfyuiLog::getUsername, imageQueryVo.getUsername())
                .likeIfPresent(ComfyuiLog::getNickname, imageQueryVo.getNickname())
                .eqIfPresent(ComfyuiLog::getMethodName, imageQueryVo.getMethodName())
                .eqIfPresent(ComfyuiLog::getState, imageQueryVo.getState())
                .betweenIfPresent(ComfyuiLog::getExcuteTime, imageQueryVo.getBegin(), imageQueryVo.getEnd())
                .orderBy(imageQueryVo.getOrderBy() == ORDERBY_EXCUTETIME, true, ComfyuiLog::getExcuteTime)
                .orderBy(imageQueryVo.getOrderBy() != ORDERBY_EXCUTETIME, false, ComfyuiLog::getExcuteTime)
        );
    }
}

